<?php

class jquery_model extends CI_Model 
{
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
	
	// Get all users from tbl_user
	function getAutocomplete( $table_name, $field_name, $term )
	{
		$this->db->select($field_name);
		$this->db->like($field_name, $term, 'both');
		$this->db->distinct();
		$this->db->limit(5);
		$query = $this->db->get($table_name);
		return $query->result();
	}
	
	function getSubscriberDetails( $field, $value )
	{
		$this->db->select( 'tbl_subscriber.subscriber_id, tbl_subscriber.first_name, tbl_subscriber.last_name, tbl_subscriber_paid.expiry_date' );
		$this->db->from( 'tbl_subscriber' );
		$this->db->join('tbl_subscriber_paid', 'tbl_subscriber_paid.subscriber_id = tbl_subscriber.subscriber_id');
		$this->db->where( $field, $value );
		$this->db->select_max('tbl_subscriber_paid.expiry_date');
		$query = $this->db->get( );
		return $query;
	}
	
	function getLoanDetails( $access_id )
	{
		$this->db->select( 'tbl_loan.access_id, tbl_loan.loan_date, tbl_loan.due_date, tbl_subscriber.first_name, tbl_subscriber.last_name, tbl_volume.title' );
		$this->db->from( 'tbl_loan' );
		$this->db->join('tbl_subscriber', 'tbl_loan.subscriber_id = tbl_subscriber.subscriber_id');
		$this->db->join('tbl_volume', 'tbl_loan.access_id = tbl_volume.access_id');
		$this->db->where( 'tbl_loan.access_id', $access_id );
		$query = $this->db->get( );
		return $query;	
	}
}

?>